//
//  MerchantViewController.m
//  StandardizedProduct
//
//  Created by 宁宁 on 16/8/3.
//  Copyright © 2016年 ym. All rights reserved.
//

#import "MerchantViewController.h"

#import "MerchantNavView.h"//导航栏View

#import "MerchantView.h"//

@interface MerchantViewController () <UIScrollViewDelegate>

@end

@implementation MerchantViewController
{
    /**页脚按钮*/
    NSMutableArray *_footerBtnArray;
    
    /**导航栏View*/
    MerchantNavView *_NavView;
    UIView *_stateview;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    _NavView.hidden = NO;
    _stateview.hidden = NO;
    
    //导航栏透明
    UIImage *image = [[UIImage alloc] init];
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    _NavView.hidden = YES;
    _stateview.hidden = YES;
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置导航栏
    [self setNav];
    
    //设置FooterView
    [self setFooterView];
    
    //设置ScrollView
    [self setScrollView];
}
#pragma mark === 设置导航栏View ===
- (void)setNav{
    _stateview = [[UIView alloc] initWithFrame:CGRectMake(0, -20, SCREEN_HEIGHT, 20)];
    _stateview.backgroundColor = APPCOLOR;
    [self.navigationController.navigationBar addSubview:_stateview];
    
    _NavView = [[[NSBundle mainBundle] loadNibNamed:@"MerchantNavView" owner:nil options:nil] lastObject];
    _NavView.frame = CGRectMake(0, 20, SCREEN_WIDTH, 44);
    _NavView.backgroundColor = [UIColor clearColor];
    _NavView.searchTextField.delegate = _NavView;
    __weak __typeof__ (self) weakSelf = self;
    __weak __typeof__ (MerchantNavView *) weakNavView = _NavView;
    _NavView.MerchantNavClick = ^(int temp, NSString *string){
        switch (temp) {
            case 0:
                [weakNavView.searchTextField resignFirstResponder];
                [weakSelf.navigationController popViewControllerAnimated:YES];
                break;
            case 1:
                NSLog(@"分类");
                break;
            case 2:
                NSLog(@"更多");
                break;
            case 3:
                NSLog(@"搜索: %@", string);
                break;
            default:
                break;
        }
    };
    [self.navigationController.view addSubview:_NavView];
}

#pragma mark === 设置FooterView ===
- (void)setFooterView{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, 50)];
    bgView.backgroundColor = BackgroundCOLOR;
    [self.view addSubview:bgView];
    
    NSArray *arr = @[@"店铺详情", @"热门分类", @"联系卖家"];
    _footerBtnArray = [NSMutableArray array];
    
    CGFloat buttonWidth = (SCREEN_WIDTH - 2) / 3;
    for (int i = 0; i < 3; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:arr[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.frame = CGRectMake(i * (buttonWidth + 1), 1, buttonWidth , 49);
        button.backgroundColor = [UIColor whiteColor];
        [button addTarget:self action:@selector(footerBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:button];
        
        [_footerBtnArray addObject:button];
    }
}

#pragma mark === 页脚 店铺详情 热门分类 联系卖家 ===
- (void)footerBtnClick:(UIButton *)sender{
    int flag = -1;
    for (int i = 0; i < 3; i++) {
        if (sender == _footerBtnArray[i]) {
            flag = i;
        }
    }
    
    switch (flag) {
        case 0:
            NSLog(@"店铺详情");
            break;
        case 1:
            NSLog(@"热门分类");
            break;
        case 2:
            NSLog(@"联系卖家");
            break;
        default:
            break;
    }
}

#pragma mark === 设置ScrollView ===
- (void)setScrollView{
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 50)];
    //实际尺寸
    scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, 700);
    scrollView.delegate = self;
    scrollView.scrollEnabled = YES;
    [self.view addSubview:scrollView];
    
    MerchantView *view = [[[NSBundle mainBundle] loadNibNamed:@"MerchantView" owner:nil options:nil] lastObject];
    view.frame = CGRectMake(0, 0, SCREEN_WIDTH, 550);
    [scrollView addSubview:view];
    
    
}

@end
